<?php
namespace App\Extend\Ali;

use Yurun\OAuthLogin\Alipay\OAuth2;


/** 支付宝小程序授权接口
 * @Author abell
 * @DateTime 2020-06-09
 * @return object
 */

class AliReg
{
    public function getToken($code){
        $appid = config('web.ali_account.appid');
        $appkey = config('web.ali_account.rsaPrivateKey');
        $aliypay_oauth = new OAuth2($appid,$appkey);
        $token = $aliypay_oauth->getAccessToken($_SESSION['YURUN_ALIPAY_STATE']);
        return $token;
    }

    public function getToken3($code){
        $aop = new AopClient();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = config('web.ali_account.appid');
        $aop->rsaPrivateKey = config('web.ali_account.rsaPrivateKey');
        $aop->alipayrsaPublicKey = config('web.ali_account.alipayrsaPublicKey');


        $request = new AlipaySystemOauthTokenRequest();
        $request->setGrantType('');
        $request->setCode($code);
        $data = $aop->execute($request);
        return $data;
    }


}
